<!--
 * @Author: 林希雨 1170893640@qq.com
 * @Date: 2023-01-02 23:47:47
 * @LastEditors: 林希雨 1170893640@qq.com
 * @LastEditTime: 2023-01-03 00:14:37
 * @FilePath: \code\html\week11\练习\信息填写-标签变更.html
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
-->
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src='https://cdn.jsdelivr.net/npm/vue@2/dist/vue.js'></script>
</head>
<style>
    input{
        outline: 0;
        border: 0;
        border-bottom: 1px solid black;
        font-size: 16px;
        width: 100px;
        text-align: center;
    }
    span{
        border-bottom: 1px solid;
        width: 100px;
        text-align: center;
        display: inline-block;
    }
</style>
<body>
    <div id="app">
        <fieldset>
            <legend>信息登记</legend>
            <p v-for="(v,k,i) in userMassge">
                <label for=""> {{k}} </label>:
                <input type="text"  v-model="val" @blur="lose(k)" v-if="isEdit&&i===selectedIndex" ref="ipt">
                <span @dblclick="edit(v,i)" v-else>{{v}}</span>

            </p>
        </fieldset>
    </div>
</body>
</html>
<script>
    let vm = new Vue({
        el : "#app",
        data:{
            userMassge:{
                "姓名":"艾希",
                "年龄":16,
                "爱好":"射箭",
                "身高":"172cm"
            },
            val:"这是输入框的内容",
            isEdit:false,
            selectedIndex:""
        },
        methods:{
            edit(v,i){
                this.isEdit = true;
                this.selectedIndex = i;
                this.val = v;
                this.$nextTick(() =>{
                    console.log(this.$refs.ipt[0].focus())
                })
            } ,
            lose(k){
                this.isEdit = false;
                this.userMassge[k] = this.val
            }
        }
    })
</script>